﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LTSMZ.life.Model;
using LTSMZ.life.BLL;

namespace LTSMZ.life.Admin.Controllers
{
    public class PImgController : Controller
    {
        //
        // GET: /PImg/
        PImgBll bll = new PImgBll();
        public ActionResult Index()
        {

            return View();
        }
        public ActionResult ShowPimg()
        {
            return View(bll.ShowPImg());
        }
        public ActionResult PImg_Add( int id)
        {
            ViewBag.id = id;
            Session["id"] = id;
            return View();
        }
        public ActionResult PImg_Addimg(FormCollection from)
        {   
            //图片上传大中小，加水印
            PImg p = new PImg();
            string locationhref = System.Configuration.ConfigurationManager.AppSettings["Upload"];
            //string path = Server.MapPath(locationhref+"/LTSMZ.life.UI/");

            locationhref += Request.Files[0].FileName;
            Request.Files[0].SaveAs(locationhref);

            p.PImgHref = Request.Files[0].FileName;
            p.PImgid = Convert.ToInt32(Session["id"]);
            p.Pzhu = Convert.ToInt32(from["Pzhu"]);
            if(bll.Add(p)>0)
            {
                return Content("<script>alert('添加成功');location.href='/Home/goods_Show'</script>");
            }
            else
            {
                return Content("<script>alert('系统繁忙');location.href='/PImg/PImg_Add'</script>");
            }
        }
    }
}
